import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

class Student {
    //1.所有属性必须要是公开的
    //2.必须要有无参的构造方法
    public int studentId;
    public String studentName;
}
@WebServlet("/json")
public class Post extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ObjectMapper objectMapper = new ObjectMapper();
        Student s = objectMapper.readValue(req.getInputStream(), Student.class);
        System.out.println(s.studentId);
        System.out.println(s.studentName);
        resp.setContentType("application/json; charset=utf8");
        resp.getWriter().write(objectMapper.writeValueAsString(s));
    }
}
